#include <iostream>
#include <future>

int Add(int num1, int num2)
{
    std::cout << "into add" << std::endl;
    return num1 + num2;
}

int main()
{
    std::cout << "ok" << std::endl;

    // std::launch::async策略: 创建一个新线程来执行任务
    // std::launch::deferred策略: 同步策略 只有在调用future::get()时才执行该任务
    // ssssstd::future<int> res = std::async(std::launch::async, Add, 210, 127);
    std::future<int> res = std::async(std::launch::deferred, Add, 210, 127);

    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout << "---------------------------" << std::endl;

    // future::get()用于获取异步函数执行的结果，没有结果则阻塞
    std::cout << res.get() << std::endl;

    return 0;
    
}